Skip to content

Make enums as sealed classes generate sealed interfaces #5921

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 28, 2024

Conversation

BoD
Copy link
Contributor

@BoD BoD commented May 27, 2024

A follow-up to #5904, this makes the Kotlin version closer to the Java one: unknown enums can only be created through safeValueOf.

@BoD BoD requested a review from martinbonnin as a code owner May 27, 2024 15:21
Copy link
Contributor

@martinbonnin martinbonnin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sealed interfaces are supported since Kotlin 1.5 so it should be ok

We might not need the OptIn marker after all. We added it initially because the UNKNOWN__ constructor was public but we might want to wait a little bit with this usage see if we really need it.

This sadly doesn't solve the case where GraphQL enums are generated as Kotlin enums. We should probably make sealedClassesForEnumsMatching.set(listOf(".*") the default but can be done in a future PR.

This is source breaking change for anyone using the UNKNOWN__() constructor directly (which was discouraged anyways). We should add a mention in the migration guide.

For all callers, it is binary breaking. If you ship a library that exposes an Apollo generated enum, it is a binary breaking change.

@BoD
Copy link
Contributor Author

BoD commented May 28, 2024

Removed the optin annotation and added something to the migration doc here

@BoD BoD merged commit 7a3c146 into java-enum-as-class-non-null-raw-value May 28, 2024
5 checks passed
@BoD BoD deleted the rework-enum-sealed-classes branch May 28, 2024 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants